<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>签到</title>
    <link rel="stylesheet" href="../../layuimini/lib/layui-v2.5.5/css/layui.css" media="all" />
    <style>
        .signin_bt {
            height: 160px;
            width: 160px;
        }
    </style>
</head>

<body>
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-md4 layui-col-md-offset4" style="text-align: center;">
                <h1>下班签退</h1>
            </div>
        </div>
        <div style="height: 60px;"></div>
        <div class="layui-row">
            <div class="layui-col-md2 layui-col-md-offset5" style="text-align: center;">
                <button id="sign_bt" class="layui-btn layui-btn-primary layui-btn-radius signin_bt">
                    <i id="sign_icon" class="" style="font-size: 50px;"></i>
                </button>
            </div>
        </div>
        <div style="height: 60px;"></div>
        <div class="layui-row">
            <div class="layui-col-md-offset4 layui-col-md4" style="text-align: center;">
                <p id="sign_message"></p>
            </div>
        </div>
    </div>

    <script src="../../layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script src="../../layuimini/js/lay-config.js" charset="utf-8"></script>
    <script>
        layui.use(['jquery', 'common'], function () {
            var common = layui.common
            var $ = layui.jquery
            var signout_bt = $('#sign_bt')
            var signout_icon = $('#sign_icon')
            var signout_msg = $('#sign_message')

            common.axios('/attendance/getAttendanceStatus', 'get', null, function (res) {
                //先判断今天是否签到
                if (res.data.data === -1) { //没有签过到不许签退
                    signout_bt.attr('class',
                        'layui-btn layui-btn-disabled layui-border-green layui-btn-radius signin_bt'
                    )
                    signout_icon.attr('class', 'layui-icon layui-icon-subtraction')
                    signout_msg.text('今天还未签到，签到之后方可签退')
                } else {
                    //获取签退状态
                    common.axios('/attendanceout/getAttendanceoutStatus', 'get', null,
                        function (res) {
                            console.log(res)
                            if (res.data.data === -1) {
                                console.log('aaa')
                                signout_bt.attr('class',
                                    'layui-btn layui-btn-normal layui-btn-radius signin_bt')
                                signout_icon.attr('class','layui-icon layui-icon-release')
                                signout_msg.text('今日未签退')
                                signout_bt.click(function(){
                                    common.axios('/attendanceout/insertAuto','post',null,function(res){
                                        console.log(11)
                                        if(res.data.code==200){
                                            //签退成功
                                            signout_bt.unbind()
                                            signout_bt.attr('class','layui-btn layui-btn-disabled layui-btn-radius signin_bt')
                                            signout_icon.attr('class','layui-icon layui-icon-ok','style','color: #1E9FFF;')
                                            signout_msg.text('签退成功')
                                        }
                                    })
                                })
                            }else{
                                signout_bt.attr('class','layui-btn layui-btn-disabled layui-btn-radius signin_bt')
                                signout_icon.attr('class','layui-icon layui-icon-ok')
                                signout_msg.text('已签退成功')
                            }
                        })
                }
            })
        })
    </script>
</body>

</html>